<template>
    <div class="app-container">
        <div class="head">
            <img src="@/assets/img/Layout/position.png" />
            <p class="see-block">BOM表清单</p>
        </div>
        <div class="view-container">
            <el-form :model="queryParams" ref="queryForm" :inline="true">
                <el-form-item label="产品名称" prop="specificationName">
                <el-input
                    v-model="queryParams.specificationName"
                    placeholder="按产品名称模糊检索"
                    clearable
                    size="small"
                    style="width: 230px;"
                    @keyup.enter.native="handleQuery"
                />
                </el-form-item>
                <el-form-item label="编码" prop="code">
                <el-input
                    v-model="queryParams.code"
                    placeholder="按编码检索"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
                />
                </el-form-item>
                <el-form-item label="状态" prop="approvalStatus" >
                    <el-select
                        v-model="queryParams.approvalStatus"
                        placeholder="全部"
                        clearable
                        size="small"
                        style="width:100px;"
                    >
                        <el-option label="待审核" value="0">待审核</el-option>
                        <el-option label="已审核" value="1">已审核</el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" class="list-search btn-success" color="#5ED4D4">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" class="list-search">重置</el-button>
                </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button
                        class="btn-success"
                        type="primary"
                        icon="el-icon-plus"
                        size="mini"
                        @click="add()"
                        v-hasPermi="['system:productBom:add']"
                    >新建</el-button>
                </el-col>
            </el-row>
            <el-table :data="list" @row-click="handleView" border>
                <el-table-column label="序号" type="index" align="center" width="50">
                    <template slot-scope="scope">
                        <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="编码"  align="center" prop="code" width="150" />
                <el-table-column label="品名" align="center" prop="specificationName" width="180" />
                <el-table-column label="规格" align="center" prop="specification" />
                <el-table-column label="单位" align="center" prop="unit" />
                <el-table-column label="物料编码" align="center" prop="specificationCode" width="150">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.detailList" :key="index">
                            {{ item.specificationCode }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="名称" align="center" prop="specificationName" width="180">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.detailList" :key="index">
                            {{ item.specificationName }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="单位" align="center" prop="unit">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.detailList" :key="index">
                            {{ item.unit }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="需求量" align="center" prop="usageAmount">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.detailList" :key="index">
                            {{ item.usageAmount }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="损耗量" align="center" prop="lossAmount">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.detailList" :key="index">
                            {{ item.lossAmount }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="是否BOM" align="center" prop="ifBom">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.detailList" :key="index">
                            {{ item.ifBom == '0' ? '否' : item.ifBom == '1' ? '是' : '' }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="BOM编号" align="center" prop="productBomCode">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.detailList" :key="index">
                            {{ item.productBomCode }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="规格尺寸" align="center" prop="specification">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.detailList" :key="index">
                            {{ item.specification }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="版本号" align="center" prop="version" />
                <el-table-column label="状态" align="center" prop="approvalStatus">
                    <template slot-scope="scope">
                        {{ scope.row.approvalStatus == '0' ? '待审核' : scope.row.approvalStatus == '1' ? '已审核' : scope.row.approvalStatus == '2' ? '反审核' : scope.row.approvalStatus == '3' ? '拒绝' : '' }}
                    </template>
                </el-table-column>
            </el-table>
            <pagination
                v-show="total > 0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
            />
        </div>
    </div>
</template>

<script>
import { bomList } from "@/api/system/bom/bom"
export default {
    name: "list",
    data() {
        return {
            // 总条数
            total: 0,
            // 列表数据
            list: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                approvalStatus: undefined,
                specificationName: undefined,
                code: undefined
            }
        }
    },
    created() {
        this.getList()
    },
    methods: {
        // 获取列表
        getList() {
            bomList(this.addDateRange(this.queryParams)).then(res => {
                this.list = res.rows
                this.total = res.total
            })
        },
        // 搜索按钮
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        // 重置按钮
        resetQuery() {
            this.resetForm("queryForm")
            this.handleQuery()
        },
        // 新建
        add(){
            this.$router.push({path:"/bom/add"})
        },
        // 查看
        handleView(row) {
            this.$router.push({path:"/bom/detail", query:{ id: row.id }})
        }
    }
}
</script>